﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using ZX.HIS.IDAL;
using ZX.HIS.DBUtility;
using System.Collections.Generic;//Please add references
namespace ZX.HIS.SQLServerDAL
{
    /// <summary>
    /// 数据访问类:AddPriOrthor
    /// </summary>
    public partial class AddPriOrthor : IAddPriOrthor
    {
        public AddPriOrthor()
        { }

        #region 自写方法
        /// <summary>
        /// 附加费用添加，返回自增ID
        /// </summary>
        /// <param name="APOModel"></param>
        /// <returns></returns>
        public int AddPriOrthorAdd(ZX.HIS.Model.AddPriOrthor APOModel)
        {
            string ComText = "Proc_AddPriOrthorAdd";
            SqlParameter[] parameters ={
                         new SqlParameter("@HospitalId",SqlDbType.Int,8){Value=APOModel.HospitalId}, 
                         new SqlParameter("@AddPriOrthorContent",SqlDbType.Int,8){Value=APOModel.AddPriOrthorContent},
                         new SqlParameter("@AddPriOrthorPrice",SqlDbType.VarChar,8){Value=APOModel.AddPriOrthorPrice},
                         new SqlParameter("@SeeDoctorId",SqlDbType.Int,8){Value=APOModel.SeeDoctorId},
                         new SqlParameter("@AddPriOrthorIsPay",SqlDbType.Int,8){Value=APOModel.AddPriOrthorIsPay}
                        };
            object obj = SqlDBhelper.RunProcedureScalar(ComText, parameters);
            if (obj != null)
            {
                return Convert.ToInt32(obj);
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// 修改附加费用
        /// </summary>
        /// <param name="APOModel"></param>
        /// <returns></returns>
        public bool AddPriOrthorUpt(ZX.HIS.Model.AddPriOrthor APOModel)
        {
            string ComText = "Proc_AddPriOrthorUpt";
            SqlParameter[] parameters ={
                         new SqlParameter("@HospitalId",SqlDbType.Int,8){Value=APOModel.HospitalId}, 
                         new SqlParameter("@AddPriOrthorContent",SqlDbType.Int,8){Value=APOModel.AddPriOrthorContent},
                         new SqlParameter("@AddPriOrthorPrice",SqlDbType.VarChar,8){Value=APOModel.AddPriOrthorPrice},
                         new SqlParameter("@SeeDoctorId",SqlDbType.Int,8){Value=APOModel.SeeDoctorId},
                         new SqlParameter("@AddPriOrthorIsPay",SqlDbType.Int,8){Value=APOModel.AddPriOrthorIsPay},
                         new SqlParameter("@AddPriOrthorId",SqlDbType.Int,8){Value=APOModel.AddPriOrthorId}
                        };
            return SqlDBhelper.RunProcedureNonQuery(ComText, parameters);
        }
        /// <summary>
        /// 根据就诊ID获取其所有附加费用信息
        /// </summary>
        /// <param name="AddPriOrthorId"></param>
        /// <returns></returns>
        public List<ZX.HIS.Model.AddPriOrthor> AddPriOrthorList(int AddPriOrthorId)
        {
            string ComText = "Proc_AddPriOrthorList";
            SqlParameter[] parameters ={
                         new SqlParameter("@AddPriOrthorId",SqlDbType.Int,8){Value=AddPriOrthorId}
                        };
            List<ZX.HIS.Model.AddPriOrthor> APOList = new List<Model.AddPriOrthor>();
            DataSet ds = SqlDBhelper.RunProcedure(ComText, parameters, "db");
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                ZX.HIS.Model.AddPriOrthor APOModel = DataRowToModel(ds.Tables[0].Rows[0]);
                APOList.Add(APOModel);
            }
            return APOList;
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ZX.HIS.Model.AddPriOrthor GetAddPriOrthorModel(int AddPriOrthorId)
        {
            string ComText = "Proc_AddPriOrthorModel";

            SqlParameter[] parameters = {
                    new SqlParameter("@AddPriOrthorId", SqlDbType.Int,4){Value=AddPriOrthorId}
            };
            DataSet ds = SqlDBhelper.RunProcedure(ComText, parameters, "db");

            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ZX.HIS.Model.AddPriOrthor DataRowToModel(DataRow row)
        {
            ZX.HIS.Model.AddPriOrthor model = new ZX.HIS.Model.AddPriOrthor();
            if (row != null)
            {
                if (row["AddPriOrthorId"] != null && row["AddPriOrthorId"].ToString() != "")
                {
                    model.AddPriOrthorId = int.Parse(row["AddPriOrthorId"].ToString());
                }
                if (row["HospitalId"] != null && row["HospitalId"].ToString() != "")
                {
                    model.HospitalId = int.Parse(row["HospitalId"].ToString());
                }
                if (row["AddPriOrthorContent"] != null)
                {
                    model.AddPriOrthorContent = row["AddPriOrthorContent"].ToString();
                }
                if (row["AddPriOrthorPrice"] != null && row["AddPriOrthorPrice"].ToString() != "")
                {
                    model.AddPriOrthorPrice = decimal.Parse(row["AddPriOrthorPrice"].ToString());
                }
                if (row["SeeDoctorId"] != null && row["SeeDoctorId"].ToString() != "")
                {
                    model.SeeDoctorId = int.Parse(row["SeeDoctorId"].ToString());
                }
                if (row["AddPriOrthorIsPay"] != null && row["AddPriOrthorIsPay"].ToString() != "")
                {
                    model.AddPriOrthorIsPay = int.Parse(row["AddPriOrthorIsPay"].ToString());
                }
            }
            return model;
        }

        #endregion
        #region  BasicMethod

        ///// <summary>
        ///// 得到最大ID
        ///// </summary>
        //public int GetMaxId()
        //{
        //return DbHelperSQL.GetMaxID("AddPriOrthorId", "tbAddPriOrthor"); 
        //}

        ///// <summary>
        ///// 是否存在该记录
        ///// </summary>
        //public bool Exists(int AddPriOrthorId)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("select count(1) from tbAddPriOrthor");
        //    strSql.Append(" where AddPriOrthorId=@AddPriOrthorId");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@AddPriOrthorId", SqlDbType.Int,4)
        //    };
        //    parameters[0].Value = AddPriOrthorId;

        //    return DbHelperSQL.Exists(strSql.ToString(),parameters);
        //}


        ///// <summary>
        ///// 增加一条数据
        ///// </summary>
        //public int Add(ZX.HIS.Model.AddPriOrthor model)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("insert into tbAddPriOrthor(");
        //    strSql.Append("HospitalId,AddPriOrthorContent,AddPriOrthorPrice,SeeDoctorId,AddPriOrthorIsPay)");
        //    strSql.Append(" values (");
        //    strSql.Append("@HospitalId,@AddPriOrthorContent,@AddPriOrthorPrice,@SeeDoctorId,@AddPriOrthorIsPay)");
        //    strSql.Append(";select @@IDENTITY");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@HospitalId", SqlDbType.Int,4),
        //            new SqlParameter("@AddPriOrthorContent", SqlDbType.VarChar,100),
        //            new SqlParameter("@AddPriOrthorPrice", SqlDbType.Decimal,9),
        //            new SqlParameter("@SeeDoctorId", SqlDbType.Int,4),
        //            new SqlParameter("@AddPriOrthorIsPay", SqlDbType.Int,4)};
        //    parameters[0].Value = model.HospitalId;
        //    parameters[1].Value = model.AddPriOrthorContent;
        //    parameters[2].Value = model.AddPriOrthorPrice;
        //    parameters[3].Value = model.SeeDoctorId;
        //    parameters[4].Value = model.AddPriOrthorIsPay;

        //    object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
        //    if (obj == null)
        //    {
        //        return 0;
        //    }
        //    else
        //    {
        //        return Convert.ToInt32(obj);
        //    }
        //}
        ///// <summary>
        ///// 更新一条数据
        ///// </summary>
        //public bool Update(ZX.HIS.Model.AddPriOrthor model)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("update tbAddPriOrthor set ");
        //    strSql.Append("HospitalId=@HospitalId,");
        //    strSql.Append("AddPriOrthorContent=@AddPriOrthorContent,");
        //    strSql.Append("AddPriOrthorPrice=@AddPriOrthorPrice,");
        //    strSql.Append("SeeDoctorId=@SeeDoctorId,");
        //    strSql.Append("AddPriOrthorIsPay=@AddPriOrthorIsPay");
        //    strSql.Append(" where AddPriOrthorId=@AddPriOrthorId");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@HospitalId", SqlDbType.Int,4),
        //            new SqlParameter("@AddPriOrthorContent", SqlDbType.VarChar,100),
        //            new SqlParameter("@AddPriOrthorPrice", SqlDbType.Decimal,9),
        //            new SqlParameter("@SeeDoctorId", SqlDbType.Int,4),
        //            new SqlParameter("@AddPriOrthorIsPay", SqlDbType.Int,4),
        //            new SqlParameter("@AddPriOrthorId", SqlDbType.Int,4)};
        //    parameters[0].Value = model.HospitalId;
        //    parameters[1].Value = model.AddPriOrthorContent;
        //    parameters[2].Value = model.AddPriOrthorPrice;
        //    parameters[3].Value = model.SeeDoctorId;
        //    parameters[4].Value = model.AddPriOrthorIsPay;
        //    parameters[5].Value = model.AddPriOrthorId;

        //    int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}

        ///// <summary>
        ///// 删除一条数据
        ///// </summary>
        //public bool Delete(int AddPriOrthorId)
        //{

        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("delete from tbAddPriOrthor ");
        //    strSql.Append(" where AddPriOrthorId=@AddPriOrthorId");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@AddPriOrthorId", SqlDbType.Int,4)
        //    };
        //    parameters[0].Value = AddPriOrthorId;

        //    int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}
        ///// <summary>
        ///// 批量删除数据
        ///// </summary>
        //public bool DeleteList(string AddPriOrthorIdlist )
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("delete from tbAddPriOrthor ");
        //    strSql.Append(" where AddPriOrthorId in ("+AddPriOrthorIdlist + ")  ");
        //    int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}


        ///// <summary>
        ///// 得到一个对象实体
        ///// </summary>
        //public ZX.HIS.Model.AddPriOrthor GetModel(int AddPriOrthorId)
        //{

        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("select  top 1 AddPriOrthorId,HospitalId,AddPriOrthorContent,AddPriOrthorPrice,SeeDoctorId,AddPriOrthorIsPay from tbAddPriOrthor ");
        //    strSql.Append(" where AddPriOrthorId=@AddPriOrthorId");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@AddPriOrthorId", SqlDbType.Int,4)
        //    };
        //    parameters[0].Value = AddPriOrthorId;

        //    ZX.HIS.Model.AddPriOrthor model=new ZX.HIS.Model.AddPriOrthor();
        //    DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
        //    if(ds.Tables[0].Rows.Count>0)
        //    {
        //        return DataRowToModel(ds.Tables[0].Rows[0]);
        //    }
        //    else
        //    {
        //        return null;
        //    }
        //}


        ///// <summary>
        ///// 得到一个对象实体
        ///// </summary>
        //public ZX.HIS.Model.AddPriOrthor DataRowToModel(DataRow row)
        //{
        //    ZX.HIS.Model.AddPriOrthor model=new ZX.HIS.Model.AddPriOrthor();
        //    if (row != null)
        //    {
        //        if(row["AddPriOrthorId"]!=null && row["AddPriOrthorId"].ToString()!="")
        //        {
        //            model.AddPriOrthorId=int.Parse(row["AddPriOrthorId"].ToString());
        //        }
        //        if(row["HospitalId"]!=null && row["HospitalId"].ToString()!="")
        //        {
        //            model.HospitalId=int.Parse(row["HospitalId"].ToString());
        //        }
        //        if(row["AddPriOrthorContent"]!=null)
        //        {
        //            model.AddPriOrthorContent=row["AddPriOrthorContent"].ToString();
        //        }
        //        if(row["AddPriOrthorPrice"]!=null && row["AddPriOrthorPrice"].ToString()!="")
        //        {
        //            model.AddPriOrthorPrice=decimal.Parse(row["AddPriOrthorPrice"].ToString());
        //        }
        //        if(row["SeeDoctorId"]!=null && row["SeeDoctorId"].ToString()!="")
        //        {
        //            model.SeeDoctorId=int.Parse(row["SeeDoctorId"].ToString());
        //        }
        //        if(row["AddPriOrthorIsPay"]!=null && row["AddPriOrthorIsPay"].ToString()!="")
        //        {
        //            model.AddPriOrthorIsPay=int.Parse(row["AddPriOrthorIsPay"].ToString());
        //        }
        //    }
        //    return model;
        //}

        ///// <summary>
        ///// 获得数据列表
        ///// </summary>
        //public DataSet GetList(string strWhere)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("select AddPriOrthorId,HospitalId,AddPriOrthorContent,AddPriOrthorPrice,SeeDoctorId,AddPriOrthorIsPay ");
        //    strSql.Append(" FROM tbAddPriOrthor ");
        //    if(strWhere.Trim()!="")
        //    {
        //        strSql.Append(" where "+strWhere);
        //    }
        //    return DbHelperSQL.Query(strSql.ToString());
        //}

        ///// <summary>
        ///// 获得前几行数据
        ///// </summary>
        //public DataSet GetList(int Top,string strWhere,string filedOrder)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("select ");
        //    if(Top>0)
        //    {
        //        strSql.Append(" top "+Top.ToString());
        //    }
        //    strSql.Append(" AddPriOrthorId,HospitalId,AddPriOrthorContent,AddPriOrthorPrice,SeeDoctorId,AddPriOrthorIsPay ");
        //    strSql.Append(" FROM tbAddPriOrthor ");
        //    if(strWhere.Trim()!="")
        //    {
        //        strSql.Append(" where "+strWhere);
        //    }
        //    strSql.Append(" order by " + filedOrder);
        //    return DbHelperSQL.Query(strSql.ToString());
        //}

        ///// <summary>
        ///// 获取记录总数
        ///// </summary>
        //public int GetRecordCount(string strWhere)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("select count(1) FROM tbAddPriOrthor ");
        //    if(strWhere.Trim()!="")
        //    {
        //        strSql.Append(" where "+strWhere);
        //    }
        //    object obj = DbHelperSQL.GetSingle(strSql.ToString());
        //    if (obj == null)
        //    {
        //        return 0;
        //    }
        //    else
        //    {
        //        return Convert.ToInt32(obj);
        //    }
        //}
        ///// <summary>
        ///// 分页获取数据列表
        ///// </summary>
        //public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("SELECT * FROM ( ");
        //    strSql.Append(" SELECT ROW_NUMBER() OVER (");
        //    if (!string.IsNullOrEmpty(orderby.Trim()))
        //    {
        //        strSql.Append("order by T." + orderby );
        //    }
        //    else
        //    {
        //        strSql.Append("order by T.AddPriOrthorId desc");
        //    }
        //    strSql.Append(")AS Row, T.*  from tbAddPriOrthor T ");
        //    if (!string.IsNullOrEmpty(strWhere.Trim()))
        //    {
        //        strSql.Append(" WHERE " + strWhere);
        //    }
        //    strSql.Append(" ) TT");
        //    strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
        //    return DbHelperSQL.Query(strSql.ToString());
        //}

        ///*
        ///// <summary>
        ///// 分页获取数据列表
        ///// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@tblName", SqlDbType.VarChar, 255),
        //            new SqlParameter("@fldName", SqlDbType.VarChar, 255),
        //            new SqlParameter("@PageSize", SqlDbType.Int),
        //            new SqlParameter("@PageIndex", SqlDbType.Int),
        //            new SqlParameter("@IsReCount", SqlDbType.Bit),
        //            new SqlParameter("@OrderType", SqlDbType.Bit),
        //            new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
        //            };
        //    parameters[0].Value = "tbAddPriOrthor";
        //    parameters[1].Value = "AddPriOrthorId";
        //    parameters[2].Value = PageSize;
        //    parameters[3].Value = PageIndex;
        //    parameters[4].Value = 0;
        //    parameters[5].Value = 0;
        //    parameters[6].Value = strWhere;	
        //    return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        //}*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

